<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Activate and deactivate error handling with exceptions</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="rarexception.isusingexceptions.html">« RarException::isUsingExceptions</a></li>
      <li style="float: right;"><a href="book.zip.html">Zip »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.rarexception.html">RarException</a></li>
    <li>Activate and deactivate error handling with exceptions</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="rarexception.setusingexceptions" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">RarException::setUsingExceptions</h1>
  <p class="verinfo">(PECL rar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">RarException::setUsingExceptions</span> &mdash; <span class="dc-title">Activate and deactivate error handling with exceptions</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-rarexception.setusingexceptions-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>RarException::setUsingExceptions</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$using_exceptions</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   If and only if the argument is <strong><code>true</code></strong>, then, instead of emitting warnings and returning a special value indicating error when the UnRAR library encounters an error, an exception of type <span class="type"><a href="class.rarexception.html" class="type RarException">RarException</a></span> will be thrown.
  </p>
  <p class="para">
   Exceptions will also be thrown for the following errors, which occur outside the library (their error code will be -1):
  </p>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     attempting some operations on a closed <span class="type"><a href="class.rararchive.html" class="type RarArchive">RarArchive</a></span> object or a <span class="type"><a href="class.rarentry.html" class="type RarEntry">RarEntry</a></span> object relative to the first;
    </span>
   </li>
   
   <li class="listitem">
    <span class="simpara">
     attempting to get an entry that does not exist with <span class="methodname"><a href="rararchive.getentry.html" class="methodname">RarArchive::getEntry()</a></span>.
    </span>
   </li>
  </ul>

 </div>


 <div class="refsect1 parameters" id="refsect1-rarexception.setusingexceptions-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">using_exceptions</code></dt>

     <dd>

      <p class="para">
       Should be <strong><code>true</code></strong> to activate exception throwing, <strong><code>false</code></strong> to deactivate (the default).
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-rarexception.setusingexceptions-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-rarexception.setusingexceptions-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-825">
    <p><strong>示例 #1 <span class="function"><strong>RarException::setUsingExceptions()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">isUsingExceptions</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$arch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">RarArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">"does_not_exist.rar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$arch</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">setUsingExceptions</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">isUsingExceptions</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$arch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">RarArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">"does_not_exist.rar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$arch</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//not&nbsp;reached<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
bool(false)

Warning: RarArchive::open(): Failed to open does_not_exist.rar: ERAR_EOPEN (file open error) in C:\php_rar\trunk\tests\test.php on line 3
bool(false)
bool(true)

Fatal error: Uncaught exception &#039;RarException&#039; with message &#039;unRAR internal error: Failed to open does_not_exist.rar: ERAR_EOPEN (file open error)&#039; in C:\php_rar\trunk\tests\test.php:8
Stack trace:
#0 C:\php_rar\trunk\tests\test.php(8): RarArchive::open(&#039;does_not_exist....&#039;)
#1 {main}
  thrown in C:\php_rar\trunk\tests\test.php on line 8
</pre></div>
    </div>
   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-rarexception.setusingexceptions-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="rarexception.isusingexceptions.html" class="methodname" rel="rdfs-seeAlso">RarException::isUsingExceptions()</a> - Check whether error handling with exceptions is in use</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>